<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  label-position="top" label-width="80px" class="demo-ruleForm" size="large" >

    <el-form-item label="ID"  prop="id">
      <el-input v-model="ruleForm.id"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Name" prop="name">
      <el-input v-model="ruleForm.name"style="width:300px"></el-input>
    </el-form-item>


    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        id: this.$route.query.id,
        name: this.$route.query.name,

      },
      rules: {
        id: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        name: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],


      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this=this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //此处需要保存添加product的全部信息
          axios({
            method:"PUT",
            url:'http://115.29.176.82:8081/manager/api/category',
            data:{
              id:_this.ruleForm.id,
              name:_this.ruleForm.name,
              description:'aa'
            }
          }).then(function (resp){
            console.log(resp)
            if(resp.status===200)
              alert('修改成功，请继续您的操作')
          })
        } else {
          alert('ERROR！请修改您的数据后再次提交')
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },



  }
}
</script>